package sanrenxing.dayEnd.backRepertoryTotal.dao;


import org.apache.ibatis.annotations.*;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SettingOfSecuritiesT;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TradingSeat;

import java.util.List;
import java.util.Map;

public interface TradingSeatDao {
    /**
     * 添加数据
     * @param tradingSeat
     * @return
     */
    @Insert("insert into tradingSeat values(seqTradingSeat.nextval,#{seatName},#{seatType},#{commRate},#{stockId},#{seataddress},#{notes})")
    public int add(TradingSeat tradingSeat);

    /**
     * 删除数据
     * @param seatId
     * @return
     */
    @Delete("delete from tradingSeat where seatId=#{seatId}")
    public int delete(@Param("seatId") int seatId);

    /**
     * 修改数据
     * @param tradingSeat
     * @return
     */
    @Update("update tradingSeat set seatName=#{seatName},seatType=#{seatType},commRate=#{commRate},stockId=#{stockId},seataddress=#{seataddress},notes=#{notes} where seatId=#{seatId}")
    public int update(TradingSeat tradingSeat);

    /**
     * 查询所有数据
     * @param map
     * @return
     */
    @Select("<script>" +
            "select  tr.seatId,tr.seatName,tr.seatType,tr.commRate,se.stockId,tr.seataddress,tr.notes from " +
            " (select rownum rn,tradingSeat.* from tradingSeat " +
            " <where>#{end}>rownum</where>) tr join settingOfSecurities se on tr.stockId=se.stockId " +
            "<where>" +
            "<if test='tradingSeat.seatName!=null'>" +
            " and seatName like '%${tradingSeat.seatName}%'" +
            "</if>" +
            "<if test='tradingSeat.seatType!=0'>" +
            " and seatType=#{tradingSeat.seatType}" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
    @Results({
            @Result(property = "seatId",column = "seatId"),
            @Result(property = "seatName",column = "seatName"),
            @Result(property = "seatType",column = "seatType"),
            @Result(property = "commRate",column = "commRate"),
            @Result(property = "stockId",column = "stockId"),
            @Result(property = "seataddress",column = "seataddress"),
            @Result(property = "notes",column = "notes")
    })
    public List<TradingSeat> queryAll(Map<String, Object> map);
    /**
     * 统计记录数
     * @param
     * @return 记录行数据
     */
    @Select("select count(*) from tradingSeat")
    public int count();

    @Select("select * from settingOfSecurities")
    public List<SettingOfSecuritiesT> querySST();

}
